package com.qf.front.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.front.biz.GoodsBiz;
import com.qf.ym.entity.GoodsEntity;
import com.qf.ym.entity.GoodsTypeEntity;
import com.qf.ym.finalstr.FruitsFinal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class GoodsController {

    @Autowired
    GoodsBiz goodsBiz;


    //查询商品列表,商品类别列表
    @RequestMapping("queryList")
    public String queryList(HttpServletRequest request){
        //一页显示8个商品数据
        PageHelper.startPage(FruitsFinal.NUM_ONE,FruitsFinal.NUM_EIGHT);

        List<GoodsEntity> goodsList = goodsBiz.queryGoodsList(null);

        request.setAttribute("goodsList",goodsList);

        //显示商品类型列表
        PageHelper.startPage(FruitsFinal.NUM_ONE,FruitsFinal.NUM_EIGHT);

        List<GoodsTypeEntity> goodsTypeList = goodsBiz.queryGoodsTypeList();

       request.setAttribute("goodsTypeList",goodsTypeList);

        return "index";
    }
    //根据条件查询
    @RequestMapping("queryGoods")
    public String queryGoodsList(GoodsEntity ge,HttpServletRequest request){

        PageHelper.startPage(FruitsFinal.NUM_ONE,FruitsFinal.NUM_EIGHT);

        List<GoodsEntity> goodsList = goodsBiz.queryGoodsList(ge);

        PageInfo<GoodsEntity>  pageInfo=new PageInfo<>(goodsList);


        request.setAttribute("pageInfo",pageInfo);

        return "/prolist";

    }
    //商品详情
    @RequestMapping("queryGoodsDetail")
    public String  goodsDetail(int goodsId,HttpServletRequest request){
           GoodsEntity goodsEntity  = goodsBiz.queryGoodsDetail(goodsId);
           request.setAttribute("goodsEntity",goodsEntity);

           return "/product";
    }
    //跳转购物车

    @RequestMapping("jumpShopCar")
    public String jumpShopCar(){
        return "/shopcart";
    }

}
